#include<bits/stdc++.h>
using namespace std;
const int N = 5010;
struct Point
{
    int x,y;
}ps[N];
int xnums[N],ynums[N],xcnt,ycnt;
int cnt[N][N];
int cnt1[N][N];
bool mark[N][N];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n,q;
    cin>>n>>q;
    for(int i = 1;i<=n;i++){ 
        cin>>ps[i].x>>ps[i].y;
        xnums[++xcnt] = ps[i].x; 
        ynums[++ycnt] = ps[i].y;
    }
    sort(xnums + 1,xnums + 1 + xcnt);
    sort(ynums + 1,ynums + 1 + ycnt);
    xcnt = unique(xnums + 1,xnums + 1 + xcnt) - xnums - 1;
    ycnt = unique(ynums + 1,ynums + 1 + ycnt) - ynums - 1;
    for(int i = 1;i <= n;i++){
        ps[i].x = lower_bound(xnums + 1,xnums + 1 + xcnt,ps[i].x) - xnums;
        ps[i].y = lower_bound(ynums + 1,ynums + 1 + ycnt,ps[i].y) - ynums;
        mark[ps[i].x][ps[i].y] = 1;
    }
    for(int i = 1;i<=xcnt;i++){
        for(int j = 1;j<=ycnt;j++){
            cnt[i][j] = cnt[i][j - 1] + mark[i][j];
        }
    }
    for(int i = 1;i<=xcnt;i++){
        for(int j = 1;j <= ycnt;j++){
            cnt1[i][j] = cnt1[i - 1][j] + mark[i][j];
        }
    }
    int ans = 0,acnt = 0;
    for(int i = 1;i<=xcnt;i++){
        for(int j = 1;j<=ycnt;j++){
            if(!mark[i][j]){
                int len = min(min(cnt[i][j],cnt[i][ycnt] - cnt[i][j]),min(cnt1[i][j],cnt1[xcnt][j] - cnt1[i][j]));
                if(len > ans){
                    acnt = 1;
                    ans = len;
                }else if(len == ans){
                    acnt++;
                }
            }
        }
    }
    if(q == 1){
        cout<<ans<<'\n';
    }else{
        if(!ans)cout<<0<<'\n';
        else cout<<acnt<<'\n';
    }
}